<template>
    <div>
        <common-banner name="杂质项目中心" en-name="Project Center"></common-banner>
        <div class="page-center">
            <div class="breadcrumb">
                <el-breadcrumb separator-class="el-icon-arrow-right" class="mt-20 mb-20">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item :to="{ path: '/products' }">产品中心</el-breadcrumb-item>
                    <el-breadcrumb-item>项目列表</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
        </div>
        <div class="menu-container">
            <ul class="menu">
                <li
                    v-for="item in projects"
                    :key="item.id"
                    :class="{ 'has-submenu': item.children && item.children.length }"
                >
                    <a
                        :href="
                            !item.children || !item.children.length ? `/stock?cate_id=${item.id}` : 'javascript:void(0)'
                        "
                        >{{ item.name }}</a
                    >
                    <ul class="submenu" v-if="item.children && item.children.length">
                        <li v-for="child in item.children" :key="child.id">
                            <a :href="`/stock?cate_id=${child.id}`">{{ child.name }}</a>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
</template>
<script setup>
import { ref } from 'vue'
import CommonBanner from '@/components/CommonBanner.vue'
// TODO 从接口中获取
const projects = ref([
    {
        id: 1,
        name: '雷帕霉素',
    },
    {
        id: 2,
        name: '阿比特龙',
    },
    {
        id: 3,
        name: '阿德福韦酯',
    },
    {
        id: 4,
        name: '阿德福韦酯一',
    },
    {
        id: 5,
        name: '雷帕霉素一',
    },
    {
        id: 6,
        name: '阿比特龙一',
        children: [
            {
                id: 60,
                name: '阿比特龙六',
            },
        ],
    },
    {
        id: 7,
        name: '阿德福韦酯二',
    },
])
</script>
<style lang="scss" scoped>
.menu-container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.menu {
    display: flex;
    flex-wrap: wrap;
    list-style: none;
    padding: 0;
    margin: 0;
    width: 100%;
}

.menu::after {
    content: '';
    flex: auto;
}

.menu li {
    flex: 0 0 20%;
    text-align: left;
    height: 42px;
    position: relative;
    margin-bottom: 20px;
    font-size: 14px;
    color: #333;
}

.menu li a {
    display: block;
    padding: 10px 0;
    text-decoration: none;
    color: #333;
}

.menu li::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 1px;
    background-color: #333;
}

.menu li:not(:nth-child(5n))::after {
    width: calc(100% + 1px);
}

.menu li:hover a {
    color: #007bff;
}

.menu li:hover::after {
    background-color: #007bff;
}

.submenu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    width: 150px;
    background: white;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    padding: 10px 0;
    z-index: 1000;
    border-radius: 4px;
    margin-top: 0px;
}

.submenu li {
    flex: none;
    width: 100%;
    height: auto;
    margin: 0;
    text-align: left;
    list-style: none;
}

.submenu li::after {
    display: none;
}

.submenu a {
    padding: 8px 15px !important;
    transition: background-color 0.3s;
}

.submenu a:hover {
    background-color: #f5f5f5;
}

.menu li:hover .submenu {
    display: block;
}

.has-submenu > a::after {
    content: '▼';
    font-size: 10px;
    margin-left: 5px;
    display: inline-block;
}

@media (max-width: 768px) {
    .page-center {
        width: auto !important;
    }
    .breadcrumb {
        margin-left: 10px;
    }

    .menu li {
        flex: 0 0 48% !important;
    }
}
</style>
